package com.cy.ajax.controller;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/")
public class AjaxController {
    private List<String> list = new ArrayList<>();
    @RequestMapping("doAjaxGet")
    public String getAjaxGet(){
        return "Ajax Get Request result";
    }
    @RequestMapping("doCheck/{name}")
    public String doCheck(@PathVariable("name") String name){
        if (list.contains(name)) {
            return name + "已存在";
        }
        return name + "可以使用";
    }
    @RequestMapping("doSave")
    public String doSave(String name){
        list.add(name);
        return name+"  saved";
    };
}
